package com.lex.manager.service.impl;

import com.lex.manager.dao.UserCustomerMapper;
import com.lex.manager.pojo.dto.PageParam;
import com.lex.manager.pojo.dto.UserCustomer;
import com.lex.manager.pojo.dto.UserCustomerResult;
import com.lex.manager.pojo.dto.UserQuery;
import com.lex.manager.pojo.po.User;
import com.lex.manager.pojo.po.UserExample;
import com.lex.manager.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserCustomerMapper userCustomerDao;
    @Override
    public User getUserByUid(Long uid) {
        return userCustomerDao.selectByPrimaryKey(uid);
    }

    @Override
    public List<User> listUsers() {
        return userCustomerDao.selectByExample(null);
    }

    @Override
    public UserCustomerResult<UserCustomer> listUserCustomerByPage(PageParam pageParam, UserQuery userQuery) {
        UserCustomerResult<UserCustomer> userCustomer=new UserCustomerResult<>();
        userCustomer.setCode(0);
        userCustomer.setMsg("查询成功");
        Integer count=userCustomerDao.countByQuery(userQuery);
        userCustomer.setCount(count);
        List<UserCustomer> userCustomerList = userCustomerDao.listUserCustomerByPage(pageParam,userQuery);
        userCustomer.setData(userCustomerList);
        return userCustomer;
    }

    @Override
    public UserCustomer getUserCustomerByUid(Long uid) {
        return userCustomerDao.getUserCustomerByUid(uid);
    }

    @Override
    public int insertUser(User user) {
        return userCustomerDao.insert(user);
    }

    @Override
    public int deleteUserByUid(Long uid) {
        return userCustomerDao.deleteByPrimaryKey(uid);
    }

    @Override
    public int deleteBatchByIds(List<Long> ids) {
        UserExample example=new UserExample();
        UserExample.Criteria criteria = example.createCriteria();
        criteria.andUidIn(ids);
        int rows = userCustomerDao.deleteByExample(example);
        return rows;
    }
}
